def is_valid_zip(zip_code):
    return len(zip_code) == 5 and zip_code.isdigit()


"""
Your function should meet the following criteria:

Do not include documents where the keyword string shows up only as a part of a larger word. 
For example, if she were looking for the keyword “closed”, you would not include the string “enclosed.”

She does not want you to distinguish upper case from lower case letters. 
So the phrase “Closed the case.” would be included when the keyword is “closed”

Do not let periods or commas affect what is matched. “It is closed.” would be included when the keyword is “closed”.
But you can assume there are no other types of punctuation.
"""


def word_search(doc_list, keyword):
    """
    Takes a list of documents (each document is a string) and a keyword.
    Returns list of the index values into the original list for all documents
    containing the keyword.

    Example:
    doc_list = ["The Learn Python Challenge Casino.", "They bought a car", "Casinoville"]
    # >>> word_search(doc_list, 'casino')
    # >>> [0]
    """
    res = []
    for s in doc_list:
        words = s.split()
        for word in words:
            if (len(word) == len(keyword) or len(word) == len(keyword) + 1) and word.lower().find(
                    keyword.lower()) != -1:
                res.append(doc_list.index(s))
                break
    return res


doc_list = ["The Learn Python Challenge Casino.", "They bought a car", "Casinoville"]
keyword = "casino"
# doc_list = ['The Learn Python Challenge Casino has a big casino full of casino games', 'They bought a car',
#             'Casinoville']
# keyword = 'casino?'
print(word_search(doc_list, keyword))


# print("The Learn Python Challenge Casino.".split())

def word_search_1(doc_list, keyword):
    # list to hold the indices of matching documents
    indices = []
    # Iterate through the indices (i) and elements (doc) of documents
    for i, doc in enumerate(doc_list):
        # Split the string doc into a list of words (according to whitespace)
        tokens = doc.split()
        # Make a transformed list where we 'normalize' each word to facilitate matching.
        # Periods and commas are removed from the end of each word, and it's set to all lowercase.
        normalized = [token.rstrip('.,').lower() for token in tokens]
        # Is there a match? If so, update the list of matching indices.
        if keyword.lower() in normalized:
            indices.append(i)
    return indices


def multi_word_search(doc_list, keywords):
    """
    Takes list of documents (each document is a string) and a list of keywords.
    Returns a dictionary where each key is a keyword, and the value is a list of indices
    (from doc_list) of the documents containing that keyword

    # >>> doc_list = ["The Learn Python Challenge Casino.", "They bought a car and a casino", "Casinoville"]
    # >>> keywords = ['casino', 'they']
    # >>> multi_word_search(doc_list, keywords)
    {'casino': [0, 1], 'they': [1]}
    """
    search_res = dict()
    for keyword in keywords:
        search_res[keyword] = word_search(doc_list, keyword)
    return search_res


doc_lists = ['The Learn Python Challenge Casino', 'They bought a car', 'Casinoville?']
keywords = ['casino']
print(word_search("casino", doc_list))
print(multi_word_search(doc_lists, keywords))
